home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / Dots & Pixels / headers / streamutils.h < prev    next >
C/C++ Source or Header  |  1995-09-29  |  3KB  |  103 lines

  1. #pragma once
  2. //
  3. // skip_spaces just does what it says. It skips spaces, tabs and the like,
  4. // but no NEWLINES on the stream mentioned. It returns the character which
  5. // stops the skipping. The character returned is put back into the input
  6. // stream.
  7. //
  8. char skip_spaces( istream &destroom);
  9. //
  10. // skip_till skips all chars up to the next occurrence of theLetter
  11. // or theString
  12. //
  13. void skip_till( istream &destroom, const char theLetter);
  14. void skip_till( istream &destroom, const char *theString);
  15. //
  16. // copy_till copies chars from input to output up to but not including
  17. // the next char
  18. //
  19. void copy_till( istream &is, ostream &os, const char theLetter);
  20. //
  21. // skip_over_newline skips all chars up to and including the next newline
  22. //
  23. void skip_over_newline( istream &destroom);
  24. //
  25. // skip_till_digit skips all chars up to but not including the next digit
  26. // skip_till_numberstart skips all characters up to but not including the
  27. // next (possible) start of a number, i.e. either a digit or a '-' or '+'.
  28. // is_possible_numberstart is an auxiliary function to test this.
  29. //
  30. void skip_till_digit( istream &destroom);
  31. void skip_till_numberstart( istream &destroom);
  32.  
  33. inline int is_possible_numberstart( const char letter)
  34. {
  35.     return( isdigit( letter) || (letter == '+') || (letter == '-'));
  36. }
  37.  
  38. #define min( a, b) (((a) < (b)) ? (a) : (b))
  39. #define max( a, b) (((a) > (b)) ? (a) : (b))
  40.  
  41. inline char *strdup( const char *string)
  42. {
  43.     char *result = new char[ strlen( string) + 1];
  44.     (void)strcpy( result, string);
  45.     return result;
  46. }
  47. //
  48. // 920224: The phrase
  49. //
  50. //     assert( (an_int >= 0) && (an_int < maxrange));
  51. //
  52. // is used (and executed, for instance in beeld::operator[])
  53. // fairly frequently. Not all compilers will know this to be equivalent to
  54. //
  55. //     assert( (unsigned int)an_int < maxrange);
  56. //
  57. // Therefore we define a function which knows of this equivalence.
  58. // It remains to be seen whether any performance is gained by this trick,
  59. // but I think 'a normal compiler' would generate faster code for it.
  60. // (fysae gives an increase of about 10%)
  61. //
  62. inline int range_check( int iks, int maxrange)
  63. {
  64.     return( (unsigned int)iks < (unsigned int)maxrange);
  65. }
  66.  
  67. #define assert_range( iks, maxrange) assert( range_check( iks, maxrange))
  68. //
  69. // a general constant used to indicate zero-ness in numerical calculations:
  70. //
  71. #define vrijwel_niets 1E-6
  72.  
  73. inline int bijnanul( const double number)
  74. {
  75.     return ((fabs( number) < vrijwel_niets));
  76. }
  77. //
  78. // 950506: some constants
  79. //
  80. const double one_pi       =         3.14159265359;
  81. const double two_pi       =   2.0 * 3.14159265359;
  82. const double two_over_pi  =   2.0 / 3.14159265359;
  83. //
  84. // 950614: conversions between degrees and radians.
  85. // Both are implemented using a multiplication since
  86. // multipliactions are (on most architectures) faster than divisions.
  87. //
  88. const double _180_over_pi = 180.0 / 3.14159265359;
  89. const double pi_over_180  = 3.14159265359 / 180.0;
  90.  
  91. double RadiansToDegrees( double rads);
  92. double DegreesToRadians( double degs);
  93.  
  94. inline double RadiansToDegrees( double rads)
  95. {
  96.     return rads * _180_over_pi;
  97. }
  98.  
  99. inline double DegreesToRadians( double degs)
  100. {
  101.     return degs * pi_over_180;
  102. }
  103.